package operator;
/**
 * @author Feri
 */
/**
 *  This class is the implementation of dividing. <br />
 * See <A href="https://sites.google.com/site/sabloanedeproiectare/refactoring" > Design Patterns Lab </A>
 */
public class Cat extends Operator{
	/**
	 * @return Returns the value of aux1/aux1 or an error message.
	 */
	public double calcul(double aux1, double aux2) {
		if(aux2 == 0){
			   System.out.println("Eroare: impartire cu zero");
			   System.exit(1);
		}
		return aux1/aux2;
	}	
	/**
	 * @return This static method returns the value of aux1/aux1 or an error message.<br />
	 */
	public static double Calcul(double aux1, double aux2){
		if(aux2 == 0){
			   System.out.println("Eroare: impartire cu zero");
			   System.exit(1);
		}
		return aux1/aux2;
	}
	/**
	 * @return Returns the value of the derivation of the (left son)/(right son)
	 */
	public double calculDerivata(){
		if (fStang == null || fDrept == null)
			System.exit(1);
		return calcul(fStang.calculDerivata(), fDrept.calculDerivata());
	}
	/**
	 * @return Returns the derivation of the (left son)/(right son)
	 */
	public String derivare(){
		if (fStang == null || fDrept == null)
			System.exit(1);
		return concatTermeni(fStang.derivare(), fDrept.derivare());
	}
	/**
	 * @return Returns the concatenation of aux1 and aux2.
	 */
	public String concatTermeni(String aux1, String aux2){
		String aux;
		if (aux1.compareTo("0") == 0 || aux2.compareTo("0") == 0)
		aux = aux1;
		else if (aux1.compareTo("0") == 0) aux = aux2;
		else if (aux2.compareTo("0") == 0 ) aux = aux1;
		else
			aux = aux1 + "/" + aux2;
		return aux;
	}
	/**
	 * Same as concatTermeni, but it is static
	 */
	public static String concatTermens(String aux1, String aux2){
		String aux;
		if (aux1.compareTo("0") == 0 || aux2.compareTo("0") == 0)
		aux = aux1;
		else if (aux1.compareTo("0") == 0) aux = aux2;
		else if (aux2.compareTo("0") == 0 ) aux = aux1;
		else
			aux = aux1 + "/" + aux2;
		return aux;
	}
}
